clear
use "Paradox_of_trad-clean-conjoint_data.dta"

*///////////////////////MAIN ANALYSIS////////////////////////////
*///////////////////////MAIN ANALYSIS////////////////////////////

//modify returnee recruitment var
label define Ethnicity 1 "Different ethnicity", modify
label define Ethnicity 2 "Same ethnicity", modify

label define IDP_was 1 "Forced fighter for extremist", modify
label define IDP_was 2 "Forced spouse for extremist", modify
label define IDP_was 3 "Forced informant for extremist", modify
label define IDP_was 4 "Forced informant for military", modify
label define IDP_was 5 "Forced informant for cJTF", modify
label define IDP_was 7 "Volunteer fighter for extremist", modify
label define IDP_was 8 "Volunteer fighter for cJTF", modify
label define IDP_was 9 "Volunteer spouse for extremist", modify
label define IDP_was 10 "Volunteer informant for extremist", modify
label define IDP_was 11 "Volunteer informant for military", modify
label define IDP_was 12 "Volunteer informant for cJTF", modify

label define Religion 1 "Different religion", modify
label define Religion 2 "Same religion", modify



//Figure 2: Effects of returnee attributes on probability of being preferred for community acceptance
conjoint accept ethnicity returnee_recruitment returnee_action religion, est(amce) id(SbjNum) base(1 6 3 1) graph

//Table II: Effect of apology and endorsement on acceptance: AMCE contrasts
/* First Additional Analyss for H1a & H1b */

* Your model (unchanged, base = 3 = No apology)
regress accept i.ethnicity ib(6).returnee_recruitment ib(3).returnee_action i.religion, vce(cluster SbjNum)

* (Sanity check: are levels as expected?)
tab returnee_action, missing
label define ract 1 "Apology + Sarki" 2 "Apology only" 3 "No apology"
label values returnee_action ract

* H1a — apology vs no apology (two simple level-vs-base contrasts)
lincom 2.returnee_action   // Apology only  minus No apology
lincom 1.returnee_action   // Apology+Sarki minus No apology

* H1b — endorsement within apologizers
lincom 1.returnee_action - 2.returnee_action   // (Apology+Sarki) – (Apology only)

* (Optional pooled test for H1a: any apology vs none)
lincom 0.5*1.returnee_action + 0.5*2.returnee_action



//Table III: Column-wise AMCEs by apology/endorsement levels
asdoc regress accept i.ethnicity ib(6).returnee_recruitment i.religion if returnee_action ==1, vce(cluster SbjNum), dec(2) cnames(Apology (Sarki accepts)) replace nest

asdoc regress accept i.ethnicity ib(6).returnee_recruitment i.religion if returnee_action ==2, vce(cluster SbjNum), dec(2) cnames(Apology) append nest

asdoc regress accept i.ethnicity ib(6).returnee_recruitment i.religion if returnee_action ==3, vce(cluster SbjNum), dec(2) cnames(No apology)append nest

OR

conjoint accept ethnicity returnee_recruitment religion, est(mm) id(SbjNum) subgroup(returnee_action) graph(3)




*****H2 TESTS (Table IV)*****

* 0) Inspect the recruitment attribute
tab returnee_recruitment, missing
label list `: value label returnee_recruitment'

* 1) Create a string version of the labeled categories
capture confirm string variable returnee_recruitment
if _rc {
    decode returnee_recruitment, gen(rr_str)
}
else {
    gen rr_str = returnee_recruitment
}

* (make matching case-insensitive)
replace rr_str = lower(rr_str)

* 2) Grouping 1: coerced_vs_vol (1 = coerced/forced, 0 = volunteer)
gen byte coerced_vs_vol = .
replace coerced_vs_vol = 1 if strpos(rr_str, "forced")
replace coerced_vs_vol = 0 if strpos(rr_str, "volunteer")

* 3) Grouping 2: role (1 = fighter, 0 = spouse OR informant)
gen byte role = .
replace role = 1 if strpos(rr_str, "fighter")
replace role = 0 if strpos(rr_str, "spouse") | strpos(rr_str, "informant")

* 4) Treat "not associated" (and anything else that isn't a returnee type) as missing for these H2 tests
replace coerced_vs_vol = . if strpos(rr_str, "not associated")
replace role           = . if strpos(rr_str, "not associated")

* 5) Optional: alignment (useful for robustness splits)
*    1 = extremist, 2 = govt forces, 3 = cjtf
gen byte align = .
replace align = 1 if strpos(rr_str, "extremist")
replace align = 2 if strpos(rr_str, "govt forces")
replace align = 3 if strpos(rr_str, "cJTF")
label define align 1 "Extremist" 2 "Govt forces" 3 "cJTF"
label values align align

* 6) Label the new dummies
label define coercl 0 "Volunteer" 1 "Coerced/Forced"
label values coerced_vs_vol coercl
label define rolecl 0 "Spouse/Informant" 1 "Fighter"
label values role rolecl

* 7) QC checks: to make sure nothing unexpected is coded
tab rr_str coerced_vs_vol, missing
tab rr_str role, missing
tab coerced_vs_vol role, missing

* Sanity: no "not associated" should be coded into either grouping
assert missing(coerced_vs_vol) if strpos(rr_str,"not associated")
assert missing(role)           if strpos(rr_str,"not associated")


//TABLE IV: Endorsement effects and cross-group contrasts
* Refit with informative bases
reg accept ib(2).returnee_action##ib(0).coerced_vs_vol ib(2).returnee_action##ib(0).role i.ethnicity i.religion if !missing(coerced_vs_vol, role), vce(cluster SbjNum)

* Endorsement effect for the BASE group (Volunteer & Spouse/Informant):
* Apology+Sarki vs Apology among volunteers & spouse/informants
lincom 1.returnee_action

lincom 1.returnee_action + 1.returnee_action#0.coerced_vs_vol   // volunteer endorsement effect
lincom 1.returnee_action + 1.returnee_action#1.coerced_vs_vol   // coerced endorsement effect

* H2a: endorsement effect within COERCED (vs volunteer)
lincom 1.returnee_action#1.coerced_vs_vol                       // coerced − volunteer (the H2a contrast)


lincom 1.returnee_action + 1.returnee_action#1.role             // fighters endorsement effect
lincom 1.returnee_action + 1.returnee_action#0.role             // spouse/informant endorsement effect

* H2b: endorsement effect within FIGHTERS (vs spouse/informants)
lincom 1.returnee_action#1.role                                 // fighters − spouse/informants (the H2b contrast)


//ROBUSTNESS:Controlling for Respondents' Characteristics

*Figure 3a-c: Results of subgroup analysis for community's acceptance of potential returnees by Gender, SES, and War Exposure

conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(gender) graph //gender status

conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(exposure_bi) graph //exposure status

conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(ses_change2) graph //exposure status


///////////////APPENDICES//////////////////
///////////////APPENDICES//////////////////


* Create a tag that marks exactly one row per respondent
bysort SbjNum: gen byte tag = (_n == 1)

* Quick checks to confirm one per id
count if tag //there are 215 respondents
assert tag == 1 if _n == 1 & SbjNum == id[_n-1] /* optional sanity check */

* 3) Descriptives
summarize age if tag, detail

*Appendix 1 (1a-1f)
asdoc tab1 age gender educ religion_full ethnicity_full ses_change2 if tag, replace

*Appendix 2: Distribution of PTS
histogram pts_index if tag, percent fcolor(gs7) lcolor(black) 

*Appendix 3:Distribution of Exposure to Violence
graph bar (meanci) viol_extremist_phy_inj viol_extremist_displaced viol_extremist_fam_inj viol_extremist_fam_kill viol_extremist_home_destr viol_jtf_phy_inj viol_jtf_displaced viol_jtf_fam_inj viol_jtf_fam_kill viol_jtf_home_destr viol_NA_phy_inj viol_NA_displaced viol_NA_fam_inj viol_NA_fam_kill viol_NA_home_destr if tag, asyvars


*Appendix 5: Estimated average marginal component effects (AMCEs)
asdoc conjoint accept ethnicity returnee_recruitment returnee_action religion, est(amce) id(SbjNum) base(1 6 3 1), dec(2) cnames(AMCE), replace //use this for appendix table for fig 2 

*Appendix 6a: Estimated Marginal Means (MMs) by Respondents' Gender
asdoc conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(gender), dec(2) cnames(Marginal Means), replace //gender status

*Appendix 6b: Estimated Marginal Means (MMs) by Change in Socioeconomic
asdoc conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(ses_change2), dec(2) cnames(Marginal Means), replace //SES

*Appendix 6c: Estimated Marginal Means (MMs) by Exposure to Violence 
asdoc conjoint accept ethnicity returnee_recruitment returnee_action religion, est(mm) id(SbjNum) subgroup(exposure_bi), dec(2) cnames(Marginal Means), replace //exposure status





